package com.work.api.bd;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.work.entity.bd.BdTeam;
import com.work.service.bd.IBdTeamService;
import com.work.vo.bd.BdTeamTreeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 队组控制器
 *
 * @author ：dujianyu
 * @since ：Created in 2024/5/20 9:03
 */
@RestController
@AllArgsConstructor
@RequestMapping("bd/team")
@Api(value = "基础数据-队组控制器", tags = "基础数据-队组控制器")
public class BdTeamController extends BladeController {

    private IBdTeamService service;

    @PostMapping("/submit")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "新增或修改", notes = "传入entity")
    public R<Boolean> saveOrUpdate(@Valid @RequestBody BdTeam entity) {
        return R.status(service.saveOrUpdate(entity));
    }

    @PostMapping("/remove")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "删除", notes = "传入id")
    public R<Boolean> remove(@ApiParam(value = "主键集合", required = true) @RequestParam String id) {
        return R.status(service.deleteLogic(Func.toLongList(id)));
    }

    @GetMapping("/tree")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "树形", notes = "")
    public R<List<BdTeamTreeVO>> tree() {
        return R.data(service.selectBdTeamTreePc());
    }

}
